import sys
from libs.exception import BaseException

class InvalidImplementationException(BaseException):
	MESSAGE = "%s is not a valid implementation";

def Factory(task, profile):
	profile = dict(profile);
	path = profile['implementation'];
	sub  = path.split('.',1);
	module = __import__(path,{},{},[sub[1]]);

	if module.klass == None: raise InvalidImplementationException(path);
	code = module.klass.__init__.im_func.func_code;
	valid_args  = code.co_varnames[0:code.co_argcount]
	print profile;
	passed_args = [ (k, v) for k, v in profile.iteritems() if k in valid_args ];
	print passed_args;
	return module.klass(**dict(passed_args));
